package com.sale.system.dubbo;

import com.sale.common.core.domain.R;
import com.sale.system.api.RemoteCodingService;
import com.sale.system.api.domain.dto.SysApiCategoryDto;
import com.sale.system.api.domain.dto.SysMaterialCodingResultDto;
import com.sale.system.domain.SysCategory;
import com.sale.system.domain.SysMaterialCoding;
import com.sale.system.service.ISysMaterialCodingService;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * 获取单个物料类别
 */
@RequiredArgsConstructor
@DubboService
@Service
public class RemoteCodingServiceImpl implements RemoteCodingService {

    private final ISysMaterialCodingService sysMaterialCodingService;

    /**
     * 获取单个物料类别信息
     * @param codingId
     * @return
     */
    @Override
    public R<SysMaterialCodingResultDto> getSysMaterialCodingById(Long codingId) {
        SysMaterialCodingResultDto sysMaterialCodingResultDto = new SysMaterialCodingResultDto();
        SysMaterialCoding sysMaterialCodingById = sysMaterialCodingService.getSysMaterialCodingById(codingId);
        BeanUtils.copyProperties(sysMaterialCodingById, sysMaterialCodingResultDto);
        return R.ok(sysMaterialCodingResultDto);
    }

    /**
     * 根据物料编码获取对应类别信息（dubbo 调用）
     * @param materialCode
     * @return
     */
    @Override
    public R<SysApiCategoryDto> getByCode(String materialCode) {
        SysApiCategoryDto sysApiCategoryDto = new SysApiCategoryDto();
        SysCategory byCode = sysMaterialCodingService.getByCode(materialCode);
        if(byCode != null){
            BeanUtils.copyProperties(byCode, sysApiCategoryDto);
        }
        return R.ok(sysApiCategoryDto);
    }
}
